import datetime

from absl import app, flags

import coin.strategy.mm.fastfeature.fast_feature_dumper as ffdump
import coin.strategy.mm.fastfeature.fast_feature_feed_spec as fffspec
import coin.strategy.mm.fastfeature.util as ffutil

FLAGS = flags.FLAGS

flags.DEFINE_string('date', None, 'date')

flags.DEFINE_string('config_filename', None, 'config_filename')

flags.DEFINE_string('machine', None, 'machine')

flags.DEFINE_string('recorder_config_filename', None, 'recorder_config_filename')

flags.DEFINE_string('time_range', None, '')

flags.DEFINE_string('prof_out', None, '')

flags.DEFINE_bool('force_fastfeed', None, '')


def main(_):
  FLAGS.use_bitmex_cached_info = True

  trading_date = datetime.datetime.strptime(FLAGS.date, "%Y%m%d")
  start_hour, end_hour = flags.FLAGS.time_range.split("-")

  start_time = trading_date + datetime.timedelta(hours=float(start_hour))
  end_time = trading_date + datetime.timedelta(hours=float(end_hour))

  if FLAGS.prof_out is not None:
    import yep
    yep.start(FLAGS.prof_out)

  ffdump.dump_single2(FLAGS.config_filename,
                      FLAGS.recorder_config_filename,
                      start_time,
                      end_time,
                      FLAGS.machine)

  if FLAGS.prof_out is not None:
    yep.stop()


if __name__ == '__main__':
  app.run(main)
